<?php

require_once 'ResidentManager.php';
	class PIView{
		

		public function checkUsers($userInput, $userPword){
			
			$conn=oci_connect("naiad","1234","localhost/XE");
			if(!$conn){
				$err = "Connection error!". var_dump(oci_error());
				echo '<script> alert("'.$err.'") </script>';
				die();
				oci_close($conn);
			}
			else{
				$flag = 0;
				$s = oci_parse($conn, "select * from users");
				oci_execute($s, OCI_DEFAULT);
				while(oci_fetch($s)){
					if(($userPword==oci_result($s,'PASSWORD'))&&((strlen(trim($userInput)))>0)&&
					($userInput==oci_result($s, 'USERNAME'))){
					$flag=1;
					$_SESSION['properlogin'] = 1;
					break;
					}
				}
	
				if($flag==1) header("Location:main.html?front.html");
				else{
					header("Location:index.php?message=error");
				}
				oci_close($conn);
			}	
		}
		
		public function checkDuplicate($snum){
			
			$conn=oci_connect("naiad","1234","localhost/XE");
			if(!$conn){
				$err = "Connection error!". var_dump(oci_error());
				echo '<script> alert("'.$err.'") </script>';
				die();
				oci_close($conn);
			}
			else{
				$s = oci_parse($conn, "select * from STUDENT");
				oci_execute($s, OCI_DEFAULT);
				while(oci_fetch($s)){
					if($snum==oci_result($s,'STUDENTNO')){
						return 1;
						break;
					}
				}
				oci_close($conn);
			}	
		}
		
		// function showMessage($flag){
			// $try=0;
			// if($flag==1){
				// echo '<script>alert("Succcessfully Added")</script>';
				// $try=1;	
				// continue;
			// }else{
				// echo  '<script>alert("Error in insertion.")</script>';
				// #$_Session['alert']="Error in insertion!";
			// }
			// if($try==1)header("Location: main.html");
			
			
		// }

			function showMessage($flag) {
				if($flag==1){
					$msg = "Successfully Added!";
					$destination = "front.html";
				}else{
					$msg = "Error in insertion!";
					$destination = "form5.php";
				}
			
				echo("<html>\n");
				echo("<head>\n");
				echo("<title>System Message</title>\n");
				echo("<meta http-equiv=\"Content-Type\" content=\"text/html;
				charset=iso-8859-1\">\n");

				echo("<script language=\"JavaScript\" type=\"text/JavaScript\">\n");
				echo("alert('$msg');\n");
				echo("window.location = ('$destination');\n");
				echo("</script>\n");
				echo("</head>\n");
				echo("<body>\n");
				echo("</body>\n");
				echo("</html>\n");
				exit;
			}

		
		
		function addResident($snum,$fnme,$lnme,$mnme,$bday,$gendr,$cstatus,$lschool,$lschtype,$religion,$class,$stfap,$schol,$stipe,$cp,$email,$hobbies,$honors,$talents,$ailments,$meds,$addres,$fdnme,$fjob,$faddress,$fincome,$flife,$femployer,$fcp,$mdnme,$mjob,$maddress,$mincome,$mlife,$memployer,$mcp,$regn,$stats,$numbro,$numsis,$order,$gnme,$gadd,$gnum,$course,$college){
			
			$fnme = strtoupper($fnme);
			$lnme = strtoupper($lnme);
			$mnme = strtoupper($mnme);
			$bday = strtoupper($bday);
			$gendr = strtoupper($gendr);
			$cstatus = strtoupper($cstatus);
			$lschool = strtoupper($lschool);
			$lschtype = strtoupper($lschtype);
			$religion = strtoupper($religion);
			$class = strtoupper($class);
			$stfap = strtoupper($stfap);
			$schol = strtoupper($schol);
			$stipe = strtoupper($stipe);
			$hobbies = strtoupper($hobbies);
			$honors = strtoupper($honors);
			$talents = strtoupper($talents);
			$ailments = strtoupper($ailments);
			$meds = strtoupper($meds);
			$addres = strtoupper($addres);
			$fdnme = strtoupper($fdnme);
			$fjob = strtoupper($fjob);
			$faddress = strtoupper($faddress);
			$flife = strtoupper($flife);
			$femployer = strtoupper($femployer);
			$mdnme = strtoupper($mdnme);
			$mjob = strtoupper($mjob);
			$maddress = strtoupper($maddress);
			$mlife = strtoupper($mlife);
			$memployer = strtoupper($memployer);
			$regn = strtoupper($regn);
			$stats = strtoupper($stats);
			$gnme = strtoupper($gnme);
			$gadd = strtoupper($gadd);
			$course = strtoupper($course);
			$college = strtoupper($college);
			$flag = ResidentManager::insertResident($snum,$fnme,$lnme,$mnme,$bday,$gendr,$cstatus,$lschool,$lschtype,$religion,$class,$stfap,$schol,$stipe,$cp,$email,$hobbies,$honors,$talents,$ailments,$meds,$addres,$fdnme,$fjob,$faddress,$fincome,$flife,$femployer,$fcp,$mdnme,$mjob,$maddress,$mincome,$mlife,$memployer,$mcp,$regn,$stats,$numbro,$numsis,$order,$gnme,$gadd,$gnum,$course,$college);
			$newObj = new PIView;
			$newObj->showMessage($flag);
			
			
		}
		
		


		
		
	}		

	

	
	
?>
